Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
just-clone
Advanced tools
The just-clone npm package is a utility for deep cloning JavaScript objects. It allows you to create a deep copy of an object, ensuring that nested objects and arrays are also cloned rather than referenced.
Deep Cloning of Objects
This feature allows you to create a deep copy of an object, ensuring that nested objects are also cloned.
const clone = require('just-clone');
const original = { a: 1, b: { c: 2 } };
const copied = clone(original);
console.log(copied); // { a: 1, b: { c: 2 } }
Deep Cloning of Arrays
This feature allows you to create a deep copy of an array, ensuring that nested arrays are also cloned.
const clone = require('just-clone');
const original = [1, [2, 3], 4];
const copied = clone(original);
console.log(copied); // [1, [2, 3], 4]
Handling of Complex Data Types
This feature ensures that complex data types like Date, RegExp, and Map are properly cloned.
const clone = require('just-clone');
const original = { a: new Date(), b: /regex/, c: new Map([[1, 'one']]) };
const copied = clone(original);
console.log(copied); // { a: Date, b: /regex/, c: Map(1) { 1 => 'one' } }
Lodash is a popular utility library that provides a wide range of functions for manipulating arrays, objects, and other data types. It includes a deep cloning function called `_.cloneDeep`, which offers similar functionality to just-clone but is part of a much larger library.
rfdc (Really Fast Deep Clone) is a lightweight and fast deep cloning library. It is designed to be a minimalistic alternative to larger libraries like lodash, focusing specifically on deep cloning performance.
clone-deep is another utility for deep cloning objects and arrays. It is similar to just-clone in terms of functionality but offers additional options for customizing the cloning process.
Part of a library of zero-dependency npm modules that do just do one thing. Guilt-free utilities for every occasion.
npm install just-clone
yarn add just-clone
Deep copies objects, arrays, maps and sets
// Deep copies objects and arrays, doesn't clone functions
import clone from 'just-clone';
var arr = [1, 2, 3];
var subObj = { aa: 1 };
var obj = { a: 3, b: 5, c: arr, d: subObj };
var objClone = clone(obj);
arr.push(4);
objClone.d.bb = 2;
obj; // {a: 3, b: 5, c: [1, 2, 3, 4], d: {aa: 1}}
objClone; // {a: 3, b: 5, c: [1, 2, 3], d: {aa: 1, bb: 2}}
FAQs
deep copies objects and arrays
The npm package just-clone receives a total of 117,312 weekly downloads. As such, just-clone popularity was classified as popular.
We found that just-clone demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.